<?php
/**
 * 借款预还管理
 */
namespace Admin\Controller\Borrow;
use Think\Controller;
use Admin\Controller\Common\BaseController;

class BorrowforecastController extends BaseController
{
	/**
	 *	管理后台菜单初始化与用户登录身份验证
	 */
//	public function _initialize()
//	{
//		session('facId','51');
//		// 判断用户是否登陆
//		if (!session('?facId'))
//		{
//			$url = 'http://' . $_SERVER['HTTP_HOST'] .'/tp_bypal/index.php';
//			redirect($url);
//			exit;
//		}
//	}


	/**
	 *	借款预还列表页
	 */
	public function borrowforecast_list() 
	{
//		$select_days = I("post.select_days","");
//		$search_array['select_days'] = $select_days;
//		$this->assign("search_array",$search_array);
//
//		if ($select_days != '')
//		{
//			$sevenDay = time()+(60*60*24*$select_days);
//		}
//		else
//		{
//			$sevenDay = time()+(60*60*24*7);
//		}
//
//		$nowTime = strtotime(date("Y-m-d",time()));
//		// $sevenDay = time()+(60*60*24*7);
//
//		$model_repay_detail = M('bypal_repay_detail');
//		$array_data = $model_repay_detail->where('end_date>="'.$nowTime.'" and end_date<="'.$sevenDay.'"')->order('end_date desc')->select();
//		foreach ($array_data as $key => $value)
//		{
//			$model_borrow_info = M('bypal_borrow_info');
//			$date_borrow_info = $model_borrow_info->where('borrow_id="'.$value['binfo_id'].'"')->find();
//
//			$model_borrow_buinessinfo = M('bypal_borrow_buinessinfo');
//			$date_borrow_buinessinfo = $model_borrow_buinessinfo->where('binfo_borrowid="'.$value['binfo_id'].'"')->find();
//
//			//	商户简称
//			$model_facilitator_info = M('bypal_facilitator_info');
//			$data_facilitator_info = $model_facilitator_info->where('id="'.$date_borrow_info['borrow_busid'].'"')->find();
//			$array_data[$key]['fac_simple_name'] = $data_facilitator_info['fac_simple_name'];
//
//			//	客户姓名
//			$array_data[$key]['buinfo_name'] = $date_borrow_buinessinfo['buinfo_name'];
//
//			//	账户余额
//			$model_balance_invest = M('bypal_balance_invest');
//			$data_balance_invest = $model_balance_invest->where('cust_id="'.$date_borrow_buinessinfo['buinfo_infotips'].'"')->find();
//			$array_data[$key]['fund_balance'] = $data_balance_invest['fund_balance'];
//
//			//	起始时间
//			$array_data[$key]['start_date'] = date('Y-m-d', $value['start_date']);
//
//			//	还款日
//			$array_data[$key]['end_date'] = date('Y-m-d', $value['end_date']);
//
//			//	状态
//			if ($value['repay_date'] == '0')
//			{
//				$array_data[$key]['repay_date'] = '未还款';
//			}
//			else
//			{
//				$array_data[$key]['repay_date'] = date('Y-m-d', $value['repay_date']);
//			}
//		}
//
//		$sum_principal = round($model_repay_detail->where('end_date>="'.$nowTime.'" and end_date<="'.$sevenDay.'" and repay_date=0')->sum('principal'), 2);
//		$sum_interest = round($model_repay_detail->where('end_date>="'.$nowTime.'" and end_date<="'.$sevenDay.'" and repay_date=0')->sum('interest'), 2);
//
//		$json_list = json_encode($array_data);
//
//		$array_sum = array();
//		$array_sum[0]['fac_simple_name'] = '未还本金:';
//		$array_sum[0]['buinfo_name'] = $sum_principal . ' 元';
//		$array_sum[0]['period_number'] = '未还利息:';
//		$array_sum[0]['start_date'] = $sum_interest . ' 元';
//		$array_sum[0]['principal'] = '未还总额:';
//		$array_sum[0]['interest'] = $sum_principal + $sum_interest . ' 元';
//		$json_sum = json_encode($array_sum);
//
//		$json =  '{"total":' . count($array_data) . ',"rows":' . $json_list . ',"footer":' . $json_sum . '}';
//		$this->assign('json_list',$json);

		$this->display();
	}

    public function borrowforecast_main(){
        $page=I("post.page","1");
        $rows=I("post.rows","10");
        $select_days=I("post.select_days",7);
        $sort = I("post.sort","end_date");
        $order = I("post.order","desc");
        $order_sql="order by ".$sort." ".$order;
        $borrowbuinessinfo=D("BorrowBuinessinfo");

        $result=$borrowbuinessinfo->forecast_repayment($select_days,$order_sql,$page,$rows);

        echo json_encode($result);

    }


}